package event;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;

public class MyFrame06 extends JFrame implements MouseMotionListener,MouseListener{
	Label lb = new Label("Mouse Location");
	Canvas cv = new Canvas();
	
	public MyFrame06(){
		this.setBounds(100, 100, 500, 500);
		
		this.add(cv,BorderLayout.CENTER);
		this.add(lb,BorderLayout.NORTH);
		cv.setBackground(Color.YELLOW);
		
		cv.addMouseMotionListener(this);
		cv.addMouseListener(this);
		this.setVisible(true);	
	}
	
	public static void main(String[] args) {
		new MyFrame06();

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		Graphics g = cv.getGraphics();
		int x = e.getX();
		int y = e.getY();
		int size=10;
		g.setColor(Color.BLACK);
		g.drawOval(x-size/2, y-size/2, size, size); // 앞 두개는 타원의 중심 좌표 x,y
		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		int x = getX();
		int y = getY();
		
		lb.setText("X : " + x + "Y : " + y);
		
	}

}
